﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract DjelatnikInGrupa typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class DjelatnikInGrupaDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<DjelatnikInGrupaDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.DjelatnikInGrupa _currentDjelatnikInGrupa = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxDjelatnikInGrupaDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxDjelatnikInGrupaErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxDjelatnikInGrupaBindingSource;
		
		/// <summary> 
		/// the DGV column associated with the IDDjelatnik property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDDjelatnikDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the IDGrupaDjelatnik property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDGrupaDjelatnikDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.Djelatnik> _IDDjelatnikList;
		
		/// <summary> 
		/// The list of selectable Djelatnik
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.Djelatnik> IDDjelatnikList
		{
			get {return this._IDDjelatnikList;}
			set 
			{
				this._IDDjelatnikList = value;
				this.uxIDDjelatnikDataGridViewColumn.DataSource = null;
				this.uxIDDjelatnikDataGridViewColumn.DataSource = this._IDDjelatnikList;
			}
		}
		
		private bool _allowNewItemInIDDjelatnikList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of Djelatnik
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDDjelatnikList
		{
			get { return _allowNewItemInIDDjelatnikList;}
			set
			{
				this._allowNewItemInIDDjelatnikList = value;
				this.uxIDDjelatnikDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.GrupaDjelatnik> _IDGrupaDjelatnikList;
		
		/// <summary> 
		/// The list of selectable GrupaDjelatnik
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.GrupaDjelatnik> IDGrupaDjelatnikList
		{
			get {return this._IDGrupaDjelatnikList;}
			set 
			{
				this._IDGrupaDjelatnikList = value;
				this.uxIDGrupaDjelatnikDataGridViewColumn.DataSource = null;
				this.uxIDGrupaDjelatnikDataGridViewColumn.DataSource = this._IDGrupaDjelatnikList;
			}
		}
		
		private bool _allowNewItemInIDGrupaDjelatnikList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of GrupaDjelatnik
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDGrupaDjelatnikList
		{
			get { return _allowNewItemInIDGrupaDjelatnikList;}
			set
			{
				this._allowNewItemInIDGrupaDjelatnikList = value;
				this.uxIDGrupaDjelatnikDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.DjelatnikInGrupa> _DjelatnikInGrupaList;
				
		/// <summary> 
		/// The list of DjelatnikInGrupa to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.DjelatnikInGrupa> DjelatnikInGrupaList
		{
			get {return this._DjelatnikInGrupaList;}
			set
			{
				this._DjelatnikInGrupaList = value;
				this.uxDjelatnikInGrupaBindingSource.DataSource = null;
				this.uxDjelatnikInGrupaBindingSource.DataSource = value;
				this.uxDjelatnikInGrupaDataGridView.DataSource = null;
				this.uxDjelatnikInGrupaDataGridView.DataSource = this.uxDjelatnikInGrupaBindingSource;				
				//this.uxDjelatnikInGrupaBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxDjelatnikInGrupaBindingSource_ListChanged);
				this.uxDjelatnikInGrupaBindingSource.CurrentItemChanged += new System.EventHandler(OnDjelatnikInGrupaBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnDjelatnikInGrupaBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentDjelatnikInGrupa = uxDjelatnikInGrupaBindingSource.Current as Entities.DjelatnikInGrupa;
			
			if (_currentDjelatnikInGrupa != null)
			{
				_currentDjelatnikInGrupa.Validate();
			}
			//_DjelatnikInGrupa.Validate();
			OnCurrentEntityChanged();
		}

		//void uxDjelatnikInGrupaBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.DjelatnikInGrupa"/> instance.
		/// </summary>
		public Entities.DjelatnikInGrupa SelectedDjelatnikInGrupa
		{
			get {return this._currentDjelatnikInGrupa;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxDjelatnikInGrupaDataGridView.VirtualMode;}
			set
			{
				this.uxDjelatnikInGrupaDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxDjelatnikInGrupaDataGridView.AllowUserToAddRows;}
			set {this.uxDjelatnikInGrupaDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxDjelatnikInGrupaDataGridView.AllowUserToDeleteRows;}
			set {this.uxDjelatnikInGrupaDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxDjelatnikInGrupaDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxDjelatnikInGrupaDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="DjelatnikInGrupaDataGridViewBase"/> class.
		/// </summary>
		public DjelatnikInGrupaDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxDjelatnikInGrupaDataGridView = new System.Windows.Forms.DataGridView();
			this.uxDjelatnikInGrupaBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxDjelatnikInGrupaErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDDjelatnikDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxIDGrupaDjelatnikDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			//this.uxIDDjelatnikBindingSource = new DjelatnikBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDjelatnikBindingSource)).BeginInit();
			//this.uxIDGrupaDjelatnikBindingSource = new GrupaDjelatnikBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDGrupaDjelatnikBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDjelatnikInGrupaDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDjelatnikInGrupaBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDjelatnikInGrupaErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxDjelatnikInGrupaErrorProvider
			// 
			this.uxDjelatnikInGrupaErrorProvider.ContainerControl = this;
			this.uxDjelatnikInGrupaErrorProvider.DataSource = this.uxDjelatnikInGrupaBindingSource;						
			// 
			// uxDjelatnikInGrupaDataGridView
			// 
			this.uxDjelatnikInGrupaDataGridView.AutoGenerateColumns = false;
			this.uxDjelatnikInGrupaDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxDjelatnikInGrupaDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDDjelatnikDataGridViewColumn,
		this.uxIDGrupaDjelatnikDataGridViewColumn			});
			this.uxDjelatnikInGrupaDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxDjelatnikInGrupaDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxDjelatnikInGrupaDataGridView.Name = "uxDjelatnikInGrupaDataGridView";
			this.uxDjelatnikInGrupaDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxDjelatnikInGrupaDataGridView.TabIndex = 0;	
			this.uxDjelatnikInGrupaDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxDjelatnikInGrupaDataGridView.EnableHeadersVisualStyles = false;
			this.uxDjelatnikInGrupaDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnDjelatnikInGrupaDataGridViewDataError);
			this.uxDjelatnikInGrupaDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDjelatnikInGrupaDataGridViewCellValueNeeded);
			this.uxDjelatnikInGrupaDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnDjelatnikInGrupaDataGridViewCellValuePushed);
			
			//
			// uxIDDjelatnikDataGridViewColumn
			//
			this.uxIDDjelatnikDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDjelatnikDataGridViewColumn.DataPropertyName = "IDDjelatnik";
			this.uxIDDjelatnikDataGridViewColumn.HeaderText = "IDDjelatnik";
			this.uxIDDjelatnikDataGridViewColumn.Name = "uxIDDjelatnikDataGridViewColumn";
			this.uxIDDjelatnikDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDjelatnikDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDjelatnikDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDGrupaDjelatnikDataGridViewColumn
			//
			this.uxIDGrupaDjelatnikDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDGrupaDjelatnikDataGridViewColumn.DataPropertyName = "IDGrupaDjelatnik";
			this.uxIDGrupaDjelatnikDataGridViewColumn.HeaderText = "IDGrupaDjelatnik";
			this.uxIDGrupaDjelatnikDataGridViewColumn.Name = "uxIDGrupaDjelatnikDataGridViewColumn";
			this.uxIDGrupaDjelatnikDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDGrupaDjelatnikDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDGrupaDjelatnikDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDDjelatnikDataGridViewColumn
			//				
			this.uxIDDjelatnikDataGridViewColumn.DisplayMember = "Naziv";	
			this.uxIDDjelatnikDataGridViewColumn.ValueMember = "ID";	
			this.uxIDDjelatnikDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDDjelatnikDataGridViewColumn.DataSource = uxIDDjelatnikBindingSource;				
				
			//
			// uxIDGrupaDjelatnikDataGridViewColumn
			//				
			this.uxIDGrupaDjelatnikDataGridViewColumn.DisplayMember = "Naziv";	
			this.uxIDGrupaDjelatnikDataGridViewColumn.ValueMember = "ID";	
			this.uxIDGrupaDjelatnikDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDGrupaDjelatnikDataGridViewColumn.DataSource = uxIDGrupaDjelatnikBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxDjelatnikInGrupaDataGridView);
			this.Name = "DjelatnikInGrupaDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDjelatnikBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxIDGrupaDjelatnikBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDjelatnikInGrupaErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDjelatnikInGrupaDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxDjelatnikInGrupaBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				DjelatnikInGrupaDataGridViewEventArgs args = new DjelatnikInGrupaDataGridViewEventArgs();
				args.DjelatnikInGrupa = _currentDjelatnikInGrupa;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class DjelatnikInGrupaDataGridViewEventArgs : System.EventArgs
		{
			private Entities.DjelatnikInGrupa	_DjelatnikInGrupa;
	
			/// <summary>
			/// the  Entities.DjelatnikInGrupa instance.
			/// </summary>
			public Entities.DjelatnikInGrupa DjelatnikInGrupa
			{
				get { return _DjelatnikInGrupa; }
				set { _DjelatnikInGrupa = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxDjelatnikInGrupaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnDjelatnikInGrupaDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxDjelatnikInGrupaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDjelatnikInGrupaDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDjelatnikInGrupaDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDjelatnikDataGridViewColumn":
						e.Value = DjelatnikInGrupaList[e.RowIndex].IDDjelatnik;
						break;
					case "uxIDGrupaDjelatnikDataGridViewColumn":
						e.Value = DjelatnikInGrupaList[e.RowIndex].IDGrupaDjelatnik;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxDjelatnikInGrupaDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnDjelatnikInGrupaDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxDjelatnikInGrupaDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDjelatnikDataGridViewColumn":
						DjelatnikInGrupaList[e.RowIndex].IDDjelatnik = (System.Int32)e.Value;
						break;
					case "uxIDGrupaDjelatnikDataGridViewColumn":
						DjelatnikInGrupaList[e.RowIndex].IDGrupaDjelatnik = (System.Int32)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
